<template>
  <view>
    <web-view fullscreen :webview-styles="webviewStyles" :src="url" :update-title="false">
    </web-view>
    <!-- #ifndef MP -->
    <view class="footer" v-if="title === '注销账号'" @click="logout">
      <button class="btn">注销账号</button>
    </view>
    <!-- #endif -->
  </view>
</template>

<script>
import { customerService } from '@/api/home/index'

export default {
  data() {
    return {
      url: '',
      title: '',
      webviewStyles: {
        height: ''
      }
    }
  },
  onLoad(e) {
    this.url = e.url
    this.title = e.title
    uni.setNavigationBarTitle({
      title: this.title
    })
    // #ifndef MP

    uni.getSystemInfo({
      success: res => {
        if (this.title === '注销账号') {
          this.webviewStyles.height = res.windowHeight - 65 + 'px'
        } else {
          this.webviewStyles.height = res.windowHeight + 'px'
        }
      }
    })
    // #endif
  },

  methods: {
    logout() {
      customerService().then(res => {
        if (res.code === 200) {
          uni.reLaunch({
            url: `/pages/mySetting/webView-im?url=${res.data.h5}&title=${res.data.robotName}`
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  z-index: 999;
  position: fixed;
  right: 0;
  bottom: 46rpx;
  width: 100%;
  height: 80rpx;

  // text-align: center;

  .btn {
    margin: 0 36rpx;
    width: calc(100% - 72rpx);
    height: 100%;
    background: #2871fc;
    border-radius: 40rpx;
    color: #fff;
    font-size: 29rpx;
  }
}
</style>
